<?php
/**
 * This file is part of the Yacms (http://www.yacms.org)
 * Copyright (c) 2019 gylr0505 (http://www.yacms.org)
 *
 * Author: 鬼一浪人 <gylr0505@163.com>
 *
 * DateTime: 19-10-24 下午8:42
 * Description:
 */
 
declare(strict_types = 1);

namespace App\Template;

class TemplateProvider
{

    /**
     * @var TemplateInterface
     */
    private $template;

    /**
     *
     * @param $id template表的主键ID
     * @param string $type
     * @return bool|void
     */
    public function generatorTemplate($id, $type = 'normal')
    {
        if ($id < 0 || !is_numeric($id)){
            return false;
        }
        if (!$type){
            return;
        }
        $types = config('template.type', null);
        if (!$types){
            return;
        }

        $class = $types[$type]['class'] ?? '';
        if (!$class || !class_exists($class)){
            return;
        }
        $this->template = new $class($id);

        return true;
    }

    /**
     * @return TemplateInterface
     */
    public function getTemplate()
    {
        return $this->template;
    }

}